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

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

b = A("b")
e = B("e")
g = B("g")
l = B("l")
d = A("d")
f = A("f")

b.x = d
e.s = g
e.t = g
g.s = e
g.t = l
l.s = e
l.t = g
d.x = f
f.x = b
assert d.x.x.x.txt == "
class A:
    def __init__(self, txt: str):
        self.x: A = None
        self.txt = txt

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

b = A("b")
e = B("e")
g = B("g")
l = B("l")
d = A("d")
f = A("f")

b.x = d
e.s = g
e.t = g
g.s = e
g.t = l
l.s = e
l.t = g
d.x = f
f.x = b
assert d.x.x.x.txt == "d"