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

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

a = A("a")
g = B("g")
m = B("m")
j = B("j")
h = B("h")
d = A("d")
b = B("b")

a.x = b
g.s = h
g.u = d
m.s = g
m.u = d
j.s = g
j.u = d
h.s = g
h.u = d
d.x = m
b.s = j
b.u = a
assert d.x.s.s.s.s.s.txt == "
class A:
    def __init__(self, txt: str):
        self.x: B = None
        self.txt = txt

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

a = A("a")
g = B("g")
m = B("m")
j = B("j")
h = B("h")
d = A("d")
b = B("b")

a.x = b
g.s = h
g.u = d
m.s = g
m.u = d
j.s = g
j.u = d
h.s = g
h.u = d
d.x = m
b.s = j
b.u = a
assert d.x.s.s.s.s.s.txt == "g"