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

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

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

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

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

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

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