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.t: B = None
        self.z: B = None
        self.txt = txt

l = A("l")
j = B("j")
k = B("k")
m = B("m")
b = A("b")

l.r = j
l.p = m
j.t = m
j.z = k
k.t = m
k.z = j
m.t = j
m.z = k
b.r = m
b.p = m
assert l.r.t.t.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.t: B = None
        self.z: B = None
        self.txt = txt

l = A("l")
j = B("j")
k = B("k")
m = B("m")
b = A("b")

l.r = j
l.p = m
j.t = m
j.z = k
k.t = m
k.z = j
m.t = j
m.z = k
b.r = m
b.p = m
assert l.r.t.t.txt == "j"