class A:
    def __init__(self, txt: str):
        self.x: B = None
        self.s: A = None
        self.txt = txt

class B:
    def __init__(self, txt: str):
        self.u: B = None
        self.txt = txt

g = A("g")
l = B("l")
c = B("c")
j = A("j")
d = A("d")
k = A("k")
h = B("h")
f = A("f")

g.x = l
g.s = d
l.u = c
c.u = l
j.x = c
j.s = g
d.x = c
d.s = k
k.x = l
k.s = j
h.u = c
f.x = c
f.s = k
assert g.x.u.u.u.u.u.u.txt == "
class A:
    def __init__(self, txt: str):
        self.x: B = None
        self.s: A = None
        self.txt = txt

class B:
    def __init__(self, txt: str):
        self.u: B = None
        self.txt = txt

g = A("g")
l = B("l")
c = B("c")
j = A("j")
d = A("d")
k = A("k")
h = B("h")
f = A("f")

g.x = l
g.s = d
l.u = c
c.u = l
j.x = c
j.s = g
d.x = c
d.s = k
k.x = l
k.s = j
h.u = c
f.x = c
f.s = k
assert g.x.u.u.u.u.u.u.txt == "l"