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

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

d = A("d")
e = B("e")
c = B("c")
j = A("j")
n = A("n")

d.x = j
d.p = j
e.u = j
c.u = n
j.x = n
j.p = n
n.x = j
n.p = d
assert e.u.p.p.p.txt == "
class A:
    def __init__(self, txt: str):
        self.x: A = None
        self.p: A = None
        self.txt = txt

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

d = A("d")
e = B("e")
c = B("c")
j = A("j")
n = A("n")

d.x = j
d.p = j
e.u = j
c.u = n
j.x = n
j.p = n
n.x = j
n.p = d
assert e.u.p.p.p.txt == "j"