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

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

a = A("a")
c = B("c")
f = A("f")
n = A("n")
k = A("k")
m = A("m")
j = B("j")
b = A("b")
e = B("e")
h = B("h")

a.r = h
c.p = n
f.r = h
n.r = h
k.r = j
m.r = j
j.p = b
b.r = e
e.p = k
h.p = m
assert h.p.r.p.txt == "
class A:
    def __init__(self, txt: str):
        self.r: B = None
        self.txt = txt

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

a = A("a")
c = B("c")
f = A("f")
n = A("n")
k = A("k")
m = A("m")
j = B("j")
b = A("b")
e = B("e")
h = B("h")

a.r = h
c.p = n
f.r = h
n.r = h
k.r = j
m.r = j
j.p = b
b.r = e
e.p = k
h.p = m
assert h.p.r.p.txt == "b"