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

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

f = A("f")
e = B("e")
j = B("j")
l = A("l")
a = A("a")
c = B("c")
g = A("g")

f.x = l
e.u = l
e.p = c
j.u = f
j.p = e
l.x = f
a.x = l
c.u = f
c.p = j
g.x = l
assert a.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.u: A = None
        self.p: B = None
        self.txt = txt

f = A("f")
e = B("e")
j = B("j")
l = A("l")
a = A("a")
c = B("c")
g = A("g")

f.x = l
e.u = l
e.p = c
j.u = f
j.p = e
l.x = f
a.x = l
c.u = f
c.p = j
g.x = l
assert a.x.x.x.txt == "l"