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

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

a = A("a")
i = B("i")
j = B("j")
c = A("c")
g = A("g")
b = A("b")

a.p = j
a.x = c
i.x = j
j.x = i
c.p = j
c.x = a
g.p = j
g.x = b
b.p = i
b.x = g
assert i.x.x.x.x.x.txt == "
class A:
    def __init__(self, txt: str):
        self.p: B = None
        self.x: A = None
        self.txt = txt

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

a = A("a")
i = B("i")
j = B("j")
c = A("c")
g = A("g")
b = A("b")

a.p = j
a.x = c
i.x = j
j.x = i
c.p = j
c.x = a
g.p = j
g.x = b
b.p = i
b.x = g
assert i.x.x.x.x.x.txt == "j"