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

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

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

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

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

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

b.p = k
a.v = e
a.r = k
g.p = i
d.p = j
k.v = c
k.r = i
i.v = b
i.r = a
e.p = j
c.p = j
j.v = g
j.r = i
assert a.v.p.v.p.txt == "i"